package de.backtomedieval.buildings;

import de.backtomedieval.R;
import de.backtomedieval.game.Costs;
import de.backtomedieval.game.Earning;
import de.backtomedieval.main.Game;
import de.backtomedieval.research.AbstractResearch;

public class Academy extends AbstractBuilding {

	private static int _healthpoints = 200;
	private static int _defense = 15;
	private static Earning earnSetting = null;
	private static Costs costSetting = null;
	private AbstractResearch toResearch;
	
	
	public Academy() {
		super(_healthpoints, _defense);
		if (costSetting == null){
			costSetting = new Costs();
			costSetting.setLumberCost(50);
			costSetting.setStoneCost(40);
			costSetting.setFoodCost(100);
			costSetting.setFoodSupply(2);
			costSetting.setGoldSupply(4);
		}
		this.setCosts(costSetting);
	}

	
	@Override
	int getDefenseBonus() {
		return 0;
	}
	@Override
	int getHealthpointsBonus() {
		return 0;
	}
	@Override
	int getIncomeBonus() {
		return 0;
	}
	
	@Override
	public String getName() {
		return Game.getString(R.string.building_academy);
	}
	
	@Override
	public int getImage() {
		return R.drawable.academy;
	}


	public AbstractResearch getToResearch() {
		return toResearch;
	}


	public void setToResearch(AbstractResearch toResearch) {
		this.toResearch = toResearch;
		if (toResearch!=null) {
			startResearch();
		}
	}

	public int getNeededPointsForResearch(AbstractResearch toResearch) {
		return  (int) (toResearch.getBaseResearchPoints() * (Math.pow(1.5,toResearch.getLevel())));
	}
	

	private void startResearch() {
		int points = getNeededPointsForResearch(toResearch);
		toResearch.setResearchPoints(points);
		toResearch.setFullResearchPoints(points);
		System.out.println("Starting Research " + toResearch.getName() + " " + toResearch.getResearchPoints() + "/" + toResearch.getFullResearchPoints() + " BASE: " + toResearch.getBaseResearchPoints());
	}
	
	public int getResearchTime(AbstractResearch toResearch) {
		int needed = getNeededPointsForResearch(toResearch);
		int time = needed / (this.getLevel()*10);
		if (needed % (this.getLevel()*10) !=0) {
			time=time+1;
		}
		return time;
	}
	
	
}
